; (function ($) {
    var methods = {
        init: function (options) {

            var $this = $(this);
            if ($this.attr("disabled")) {
                return;
            }

            var setting = {
                confirm: null,
                multy: false,
                style: "wmp-iradio",
                title: window.LangMsg['msg_wmp_choose_data'],
                search_url: "",
                url: "",
                init: {
                    no: "",
                    name: ""
                },
                leaf_load: true,
                circle: false,
                circle_style: "",
                wechat_company: false,
                type: "",
                param: {
                    Language: "",
                    Country: "",
                    Parent: ""
                },
                edit: false
            };

            setting = $.extend(setting, options);
            if (setting.multy) {
                setting.style = "wmp-ickeck";
            }

            if (setting.circle) {
                setting.circle_style = "circle";
            }

            var default_place = window.LangMsg['msg_wmp_please_select_staff'];//"请选择人员";

            $this.each(function () {
                default_place = $(this).attr("title") ? $(this).attr("title") : "";
                var _html = '<div class="input-group" style="width:100%"><input type="text" class="form-control selector_text" ';
                if (!setting.edit) {
                    _html += ' disabled="disabled" ';
                } else {
                    _html += ' oninput="_input_change(this);" onpropertychange="_input_change(this);" ';
                }
                _html += ' placeholder="' + default_place + '"/><span class="input-group-btn"><button type="button" class="btn btn-default selector_button"><i class="fa fa-search"></i></button></span></div> ';
                $(this).html(_html);
            });

            $this.find("button.selector_button").click(function () {
                var wmpSelector = $($(this).parent().parent().parent());
                var frontObj = wmpSelector.find(".selector_text").attr("select_val"); //重新选人之前的对象
                Positioin_object = wmpSelector;
                if (wmpSelector.attr("disabled")) return;
                var selector_text = wmpSelector.find(".selector_text");
                AJAX('/Content/Resources/html/wmpUserSelector.html',undefined , function (d) {
                    var html = d;
                    var dialog = null;
                    top.layer.open({
                        type: 1,
                        title: '<span class="layer_back"></span><span>' + setting.title + '</span>',
                        content: html,
                        anim: 'fadeIn',
                        success: function (layero, index) {
                            Fix_Position(false);

                            setTimeout(function () {
                                var win_width = $(this).width();
                                if (win_width < 768) {
                                    $("div.layermchild").css({ "width": $(this).width() + "px" });
                                }
                            }, 100);

                            TransAll(layero);
                            dialog = $(layero);
                            dialogResize(dialog, 996, 520, 50);

                            var content_id = dialog.find("div.layui-content").attr("id");
                            dialog.attr("lay-id", content_id);

                            ieInit(dialog);

                            var index = dialog.attr("index");
                            var win_width = $(window).width();

                            var nid = $.nd();
                            var layId = 'lay' + nid;
                            var selId = 'sel' + nid;
                            var layui_content = dialog.find(".layui-content");
                            var layui_selected = dialog.find(".layui-selected");
                            layui_content.attr('id', layId);
                            layui_selected.attr('id', selId);

                            var myScroll = null;
                            var myScrollSelect = null;

                            var g_no = '';
                            var g_name = '';
                            var p_name = setting.init.name;
                            var p_no = setting.init.no;

                            var filtersearch = dialog.find(".filter-search"); //搜索面板
                            var searchControl = dialog.find(".searchControl");//搜索框
                            var searchClear = dialog.find(".filter-search-clear");//清除按钮
                            var filtermain = dialog.find(".filter-main"); //主内容
                            var filterlayer = dialog.find(".filter-search-layer"); //搜索内容

                            var listdeptuser = dialog.find(".list-dept-user");
                            var selectedflexlist = dialog.find(".selected-flex-list");

                            initSelector();

                            renderHtml(setting.url, p_no, 0);

                            dialog.find("button.save").focus();
                            //初始化列表滚动事件
                            function refreshScroll() {
                                if (win_width < 768) {
                                    if (myScroll) {
                                        myScroll.refresh();
                                    } else {
                                        myScroll = new IScroll('#' + layId, {
                                            scrollbars: false, click: true, tap: true, preventDefault: false, scrollX: true
                                        });
                                    }
                                }
                            }

                            //初始化用户滚动事件
                            function refreshSelectScroll() {
                                if (win_width < 768) {

                                    var sel_width = 0;
                                    var items = selectedflexlist.find("a");
                                    $(items).each(function (index, item) {
                                        sel_width += $(item).width();
                                    });
                                    selectedflexlist.width(sel_width);

                                    if (myScrollSelect) {
                                        myScrollSelect.refresh();
                                    } else {
                                        myScrollSelect = new IScroll('#' + selId, {
                                            scrollbars: false, click: true, tap: true, preventDefault: false, scrollX: true
                                        });
                                    }
                                }
                            }
                            //初始化已经选择的信息
                            function initSelector() {
                                var select_val = selector_text.attr("select_val");
                                if (!select_val) {
                                    var _val = selector_text.val().trim();
                                    if (!_val) { return; }
                                    select_val = JSON.stringify([{
                                        "name": _val,
                                        "no": _val,
                                        "pname": "",
                                        "pno": ""
                                    }]);
                                }
                                var set_item = JSON.parse(select_val);
                                if (!set_item || set_item.length == 0) { return; }

                                var html = "";
                                $(set_item).each(function (index, item) {
                                    var name_val = item.name;
                                    if (!name_val) { name_val = item.no; }

                                    var data_render = "";
                                    if (item.data) {
                                        data_render = "data = " + JSON.stringify(item.data);
                                    }
                                    html += '<a ' + data_render + ' href="javascript:;" no="' + item.no + '"  name="' + name_val + '" p_no="' + item.pno + '" p_name="' + item.pname + '" four_center_id="' + item.four_center_id + '" four_center_name="' + item.four_center_name + '" system_name="' + item.system_name + '" class="' + setting.circle_style + '" level="' + (item.level || '') + '"><span>' + name_val + '</span><i class="closed"></i></a>';
                                });

                                selectedflexlist.html(html);
                                selectedflexlist.find("a").unbind().bind("click", removeSelectedUser);
                                initSelectedNumber();

                                refreshSelectScroll();
                            }
                            //获取面板HTML
                            //data 数据  type:{0:默认，1：搜索}
                            function getPanelHtml(data, type) {
                                /*存在设置的值，则在查到对应的页面数据时，完善不完全的数据*/
                                var set_item = [];
                                var select_val = selector_text.attr("select_val");
                                if (select_val && select_val.length > 0) {
                                    set_item = JSON.parse(select_val);
                                    if (!set_item || set_item.length == 0) { set_item = []; }
                                }

                                var set_data = [];

                                var html = '<div class="filter-div"><ul class="filter-ul">';
                                data.each(function (i, o) {
                                    var len = selectedflexlist.find('a[no="' + this.No + '"]').length, selector_css = "";
                                    selector_css = (len > 0 ? "selected" : "");
                                    if (!this.DeptPName) {
                                        this.DeptPName = "";
                                    }
                                    if (this.IsDept == 0 && setting.leaf_load) {/*渲染叶节点数据*/
                                        var node_name = "";
                                        if (setting.type == "project" || setting.type == "cost") {
                                            node_name = this.Name;
                                        } else {
                                            node_name = this.Name + '（' + this.No + '）';
                                        }

                                        var data_content = "";
                                        if (o.Data) {
                                            data_content = ' data =' + encodeURIComponent(JSON.stringify(o.Data));
                                        }
                                        var all_data = ' all_data =' + encodeURIComponent(JSON.stringify(o));

                                        html += '<li ' + data_content + ' class="filter-user male  ' + selector_css + '" no="' + this.No + '" name="' + this.Name + '" p_no="' + this.DeptPNo + '" p_name="' + this.DeptPName + '" four_center_id="' + this.FourCenterID + '" four_center_name="' + this.FourCenterName + '" system_name="' + this.SystemName + '" ' + all_data + '><div class="filter-flex-area"><i></i><span class="user">' + (this.IsDepart == 1 ? '<font style="color:#c80000">[离职]</font>' + node_name : node_name) + '</span>' + '<span class="porg">' + (win_width < 768 ? this.DeptPName : $([this.CompanyName || '', this.DeptPName || '', this.FEmail || '', this.FPostName || '', this.ManagerName || '']).filter(function (i, o) { return o; }).toArray().join(' / ')) + '</div><div class="filter-button"><a class="' + setting.style + '"><label></label></a></div></li>';

                                        if (selector_css.length > 0 && set_item.length > 0) {
                                            $(set_item).each(function (index, item) {
                                                if (item.no == o.No) {
                                                    item.no = o.No;
                                                    item.name = o.Name;
                                                    item.pname = o.DeptPName;
                                                    item.pno = o.DeptPNo;
                                                    item.four_center_id = o.FourCenterID;
                                                    item.four_center_name = o.FourCenterName;
                                                    item.system_name = o.SystemName;
                                                    if (o.Data) {
                                                        item.data = JSON.parse(o.Data);
                                                    }
                                                    selectedflexlist.find('a[no="' + o.No + '"]>span').html(o.Name);
                                                    selectedflexlist.find('a[no="' + o.No + '"]').attr("data", encodeURIComponent(JSON.stringify(o.Data)));
                                                }
                                            });
                                        }
                                    }
                                    if (this.IsDept == 1) {/*渲染非叶节点数据*/
                                        if (setting.leaf_load) {
                                            html += '<li class="filter-org" name="' + this.Name + '" no="' + this.No + '" p_name="' + this.DeptPName + '" p_no="' + this.DeptPNo + '" level="' + (this.Level || '') + '"><div class="filter-flex-area"><i></i><span class="org">' + this.Name + '</span><span class="porg">' + this.DeptPName + '</span></div></li>';
                                        } else {
                                            html += '<li class="filter-dept ' + selector_css + '" name="' + this.Name + '" no="' + this.No + '" p_name="' + this.DeptPName + '" p_no="' + this.DeptPNo + '" level="' + (this.Level || '') + '"><div class="filter-flex-area"><i></i><span class="org">' + this.Name + '</span><span class="porg">' + this.DeptPName + '</span></div><div class="filter-button"><a class="' + setting.style + '"><label></label></a></div></li>';
                                        }
                                    }
                                    if (i == 0) {
                                        g_no = this.GrandNo;
                                        g_name = this.GrandName;
                                    }
                                });
                                html += '</ul></div>';

                                if (set_item.length > 0) {
                                    var set_text = "";
                                    var show_userid = wmpSelector.attr("show-userid");
                                    $(set_item).each(function (index, item) {
                                        if (show_userid) {
                                            set_text += item.name + "(" + item.no + ")" + ",";
                                        } else {
                                            set_text += item.name + ",";
                                        }
                                    });
                                    if (set_text.length > 0) {
                                        set_text = set_text.substring(0, set_text.length - 1);
                                    }
                                    selector_text.val(set_text).attr("select_val", JSON.stringify(set_item));
                                }

                                return html;
                            }
                            //搜索点击部门
                            function Next_Active() {
                                var click_item = $(this);
                                if (!setting.leaf_load) {
                                    click_item = $(this).parent();
                                };
                                p_no = click_item.attr("no");
                                p_name = click_item.attr("name");
                                filtersearch.removeClass("active").removeClass("inputClear");
                                filtermain.show();
                                filterlayer.hide();
                                searchControl.val('');

                                if (setting.wechat_company) {
                                    click_item.find("div.filter-button").click();
                                } else {
                                    renderHtml(setting.url, p_no, 0);
                                }
                            }
                            //返回上一节点
                            dialog.find(".layer_back").click(function () {
                                if (setting.init.no == p_no)
                                    return;

                                p_no = g_no;
                                p_name = g_name;
                                if (p_no.length > 0) {
                                    renderHtml(setting.url, p_no, 0);
                                }
                            });
                            //点击选中最终项
                            function Select_Active() {
                                selectedflexlist.width("auto");

                                var active_item;
                                if (setting.leaf_load) {
                                    active_item = $(this);
                                } else {
                                    active_item = $(this).parent();
                                }
                                var select_no = active_item.attr("no");
                                var select_name = active_item.attr("name");
                                var select_p_no = active_item.attr("p_no");
                                var select_p_name = active_item.attr("p_name");
                                var select_four_center_id = active_item.attr("four_center_id");
                                var select_four_center_name = active_item.attr("four_center_name");
                                var select_system_name = active_item.attr("system_name");
                                var select_level = active_item.attr("level");
                                var has = active_item.hasClass("selected");

                                if (setting.url.indexOf("user") > -1) {
                                    if (window.LangType != 'CN') {
                                        var sel_data = JSON.parse(decodeURIComponent(active_item.attr("all_data")));
                                        if (sel_data) {
                                            if (sel_data.EnglishName) {
                                                select_name = sel_data.EnglishName;
                                            }
                                            select_p_no = sel_data.FiveDeptID;
                                            select_p_name = sel_data.FiveDeptName;
                                            select_four_center_id = sel_data.FourCenterID;
                                            select_four_center_name = sel_data.FourCenterName;
                                            select_system_name = sel_data.SystemName;
                                            select_level = sel_data.Level;
                                        }
                                    }
                                }


                                if (has) {
                                    active_item.removeClass("selected");
                                    selectedflexlist.find('a[no="' + select_no + '"]').remove();
                                } else {
                                    var item_html = '<a href="javascript:;" no="' + select_no + '"  name="' + select_name + '" p_no="' + select_p_no + '" p_name="' + select_p_name + '" four_center_id="' + select_four_center_id + '" four_center_name="' + select_four_center_name + '" system_name="' + select_system_name + '" class="' + setting.circle_style + '" data=' + active_item.attr("data") + ' level="' + (select_level || '') + '"><span>' + select_name + '</span><i class="closed"></i></a>';

                                    if (!setting.multy) {
                                        dialog.find('ul li').removeClass("selected");
                                        selectedflexlist.html("");
                                        selectedflexlist.html(item_html);
                                    } else {
                                        selectedflexlist.append(item_html);
                                    }
                                    active_item.addClass("selected");
                                    selectedflexlist.find("a").unbind().bind("click", removeSelectedUser);
                                }
                                initSelectedNumber();

                                refreshSelectScroll();

                                dialog.find("button.save").focus();
                            }
                            //删除选中的用户
                            function removeSelectedUser() {
                                var selectorUser = $(this);
                                selectorUser.remove();
                                dialog.find('ul li[no="' + selectorUser.attr("no") + '"]').removeClass("selected");
                                initSelectedNumber();

                                refreshSelectScroll();

                                dialog.find("button.save").focus();
                            }
                            //初始化选择用户数量
                            function initSelectedNumber() {
                                var selectednumber = dialog.find(".selected-number"); //选择用户
                                var len = selectedflexlist.find("a").length;
                                if (len > 0) {
                                    selectednumber.text('(' + len + ')');
                                } else {
                                    selectednumber.text('');
                                }
                            }
                            //搜索框获取焦点
                            searchControl.focus(function () {
                                filtersearch.addClass("active");
                                filtermain.hide();
                                filterlayer.show();
                                if (searchControl.val().length == 0) {
                                    searchTip();
                                }
                            });
                            //显示搜索提示面板
                            function searchTip() {
                                filterlayer.html('<div class="search-empty-tip"><img src="/Content/img/search_tip.png" /><p></p></div>');
                            }
                            //取消搜索
                            dialog.find(".filter-search-cancel").click(function () {
                                filtermain.show();
                                filterlayer.hide();
                                filtersearch.removeClass("active").removeClass("inputClear");
                                searchControl.val('');
                                filterlayer.html('');

                                dialog.find("i.filter-search-clear").hide();
                                ieInit(dialog);
                            });
                            //清空
                            searchClear.click(function () {
                                setting.param.Search = "";
                                searchControl.val('');
                                $(this).hide();
                            });
                            //输入文字,及时搜索
                            searchControl.on('input', function () {
                                if ($(this).prop('comStart')) return;
                                var value = $(this).val();
                                searchStart();
                            }).on('compositionstart', function () {
                                $(this).prop('comStart', true);
                            }).on('compositionend', function () {
                                $(this).prop('comStart', false);
                                if (!isIE()) {
                                    searchStart();
                                }
                            });
                            //查询开始
                            function searchStart() {
                                var parent_div = searchControl.parent();
                                var text = searchControl.val().replace(/[\%\^\&\*\{\}\:\"\L\<\>\?\|\+\.]/g, '');
                                var len = text.length;
                                if (len > 0) {
                                    parent_div.addClass("inputClear");
                                    searchClear.show();
                                    if (!isNaN(text) && len < 5) return;
                                    if (setting.type == 'user' || setting.type == 'dept') {
                                        var url = [setting.search_url, $.trim(text), setting.init.no].join('/')
                                        renderHtml(url, '', 1);
                                    } else if (setting.type == 'project') {
                                        var url = [setting.search_url, $.trim(text), setting.init.companyCode].join('/')
                                        renderHtml(url, '', 1);
                                    }
                                    else {
                                        renderHtml(setting.search_url, text, 1);
                                    }
                                } else {
                                    parent_div.removeClass("inputClear");
                                    searchClear.hide();
                                }
                            }
                            //渲染显示html ui
                            function renderHtml(url, text, type, data) {
                                if (setting.type == "cost") {
                                    if (!setting.param.Country) {
                                        setting.param.Country = "cn";
                                    }

                                    if (!text) {
                                        text = "MR";
                                    }
                                    if (type == 1) {
                                        setting.param.Parent = "";
                                        setting.param.Search = text;
                                    } else {
                                        setting.param.Parent = text;
                                        setting.param.Search = "";
                                    }

                                    data = setting.param;
                                    text = "";
                                } else {
                                    if (!data) {
                                        data = {};
                                        data.Search = text;
                                    }

                                    if (!text) {
                                        text = "";
                                    } else {
                                        text = "/" + text;
                                    }
                                }

                                AJAXAPI(url + text, data, function (d, set) {
                                    //废弃 响应慢于后发的请求结果
                                    if (set) {
                                        if (set.callTime < window._callTime) {
                                            return;
                                        }
                                        window._callTime = set.callTime;
                                    }

                                    if ($(d).length > 0) {
                                        var html = getPanelHtml($(d), type), container;
                                        if (type == 0) {
                                            container = listdeptuser;
                                        } else {
                                            container = filterlayer;
                                        }
                                        container.html(html);

                                        refreshScroll();

                                        var next_item = "li.filter-org", select_item = "li.filter-user";
                                        if (!setting.leaf_load) {
                                            next_item = "li div.filter-flex-area", select_item = "li div.filter-button";
                                        }
                                        //加载下级数据
                                        container.find(next_item).bind("click", Next_Active);
                                        //选中当前点击项
                                        container.find(select_item).bind("click", Select_Active);

                                        fixIEList(dialog);

                                        if (type == 1) {
                                            //searchControl.blur().focus();
                                        }
                                    } else {
                                        if (type == 1) {
                                            searchTip();
                                        } else {
                                            ShowError(window.LangMsg['msg_app_no_data']);
                                        }
                                    }
                                });
                            };
                            //确定选择
                            dialog.find(".save").click(function () {
                                var select_item = selectedflexlist.find("a");
                                var select_result = [];
                                var s_text = "";
                                var s_p_name = "";//所属部门名称
                                var s_p_code = "";//所属部门编码

                                /*判断输出模式-是否需要带出工号*/
                                var show_userid = wmpSelector.attr("show-userid");

                                select_item.each(function (index, item) {
                                    var push_data = {
                                        name: $(item).attr("name"),
                                        no: $(item).attr("no"),
                                        pname: $(item).attr("p_name"),
                                        pno: $(item).attr("p_no"),
                                        four_center_id: $(item).attr("four_center_id"),
                                        four_center_name: $(item).attr("four_center_name"),
                                        system_name: $(item).attr("system_name"),
                                        level: $(item).attr('level')
                                    };

                                    if ($(item).attr("data") != undefined && $(item).attr("data") != "undefined") {
                                        //push_data.data = JSON.parse($(item).attr("data"));
                                        push_data.data = JSON.parse(decodeURIComponent($(item).attr("data")));
                                    }
                                    select_result.push(push_data);

                                    if (selector_text.parents("#Header_applicantUser").length > 0) {
                                        s_text += $(item).attr("name") + "(" + $(item).attr("no") + ")" + ",";
                                    } else {
                                        if (show_userid) {
                                            s_text += $(item).attr("name") + "(" + $(item).attr("no") + ")" + ",";
                                        } else {
                                            s_text += $(item).attr("name") + ",";
                                        }
                                    }


                                    s_p_name += $(item).attr("p_name") + ",";
                                    s_p_code += $(item).attr("p_no") + ",";
                                });

                                if (s_p_name != "") {
                                    s_p_name = s_p_name.substring(0, s_p_name.length - 1);
                                }

                                if (s_p_code != "") {
                                    s_p_code = s_p_code.substring(0, s_p_code.length - 1);
                                }

                                if (s_text != "") {
                                    s_text = s_text.substring(0, s_text.length - 1);
                                }

                                selector_text.val(s_text).attr("select_val", JSON.stringify(select_result));

                                ///刘亚平修改  将确定事件放置到选人控件div属性中
                                if ($.isFunction(setting.confirm)) {
                                    Fix_Position(true);
                                    setting.confirm(select_result, wmpSelector);
                                    Fix_Position(true, wmpSelector.offset().top);
                                }
                                ///判断div 是否定义confirm属性 如果有定义就调用
                                if (wmpSelector.attr("confirm") != "" && wmpSelector.attr("confirm") != undefined) {
                                    var wmpSelectorConfirm = null;
                                    eval("wmpSelectorConfirm=" + wmpSelector.attr("confirm"));
                                    if ($.isFunction(wmpSelectorConfirm)) {
                                        Fix_Position(true);
                                        wmpSelectorConfirm(select_result, wmpSelector, frontObj);
                                        Fix_Position(true, wmpSelector.offset().top);
                                    }
                                }
                                var container_div = selector_text.parent().parent();
                                var joindepttext = container_div.attr("joindepttext");
                                var joindeptvalue = container_div.attr("joindeptvalue");

                                if (joindepttext != undefined && joindepttext != "" && $("#" + joindepttext).length > 0) {
                                    $("#" + joindepttext).val(s_p_name);
                                }

                                if (joindeptvalue != undefined && joindeptvalue != "" && $("#" + joindeptvalue).length > 0) {
                                    $("#" + joindeptvalue).val(s_p_code);
                                }

                                $("div[lay-id='" + content_id + "']").remove();
                                top.layer.close(index);
                            });

                            //ie fix
                            function ieInit(container) {
                                if (!isIE()) { return; }
                                container.find("div.selected-flex").css({ "float": "left" });
                                container.find("div.selected-flex-button").css({ "float": "left" });
                                container.find("div.selected-flex").css("width", (container.find(".layui-content").width() - 10 - container.find("div.selected-flex-button").width()));
                            };
                            //ie fix
                            function fixIEList(container) {
                                if (!isIE() && !isFiefox()) { return; }

                                var dialog_width = container.width();
                                var checkbox_width = container.find("div.filter-button:first").width();
                                var line_width = dialog_width - checkbox_width;
                                container.find("div.filter-flex-area").css({ "width": line_width, "float": "left" });
                            };
                        }
                    });
                }, "GET");
            });
            ///添加默认值赋值
            $this.each(function (idex, item) {
                if ($(this).attr("defaultValue") != undefined && $(this).attr("defaultText") != undefined) {
                    if ($(this).attr("defaultValue") != "" && $(this).attr("defaultText") != "") {
                        var data = [];
                        data.push({
                            Text: $(this).attr("defaultText"),
                            Value: $(this).attr("defaultValue"),
                        });
                        $(this).WmpSelect("set", data);
                    }
                }
            })

            $this.attr("setting", JSON.stringify(setting, function (key, val) {
                if (typeof val === 'function') {
                    return val + '';
                }
                return val;
            }));

            return $this;
        },
        enable: function (options) {
            $(this).find("input.temp_hide").remove();
            $(this).find("div.input-group").show();
            return $(this);
        },
        disabled: function (options) {
            $(this).each(function () {
                var $this = $(this);
                if ($this.find("input.temp_hide").length > 0) {
                    return;
                }
                var item_obj = $this.find("div.input-group");
                var hide_text = item_obj.find("input").val();
                $this.prepend("<input style='font-size:12px;' type=\"text\" class=\"form-control temp_hide\" readonly=\"readonly\" value=\"" + hide_text + "\" disabled />");
                item_obj.hide();
            });
            return $(this);
        },
        readonly: function (options) {
            $(this).each(function () {
                var $this = $(this);

                if ($this.find("input.temp_hide").length > 0) {
                    return;
                }
                var item_obj = $this.find("div.input-group");
                var hide_text = item_obj.find("input").val();
                $this.text(hide_text);
                item_obj.hide();
            });
            return $(this);
        },
        get: function () {
            var wmpSelector = $(this).find("input.selector_text");
            if (wmpSelector.length == 0) {
                return [];
            }
            if (wmpSelector.attr("select_val") == undefined) {
                return [];
            }
            if (wmpSelector.attr("select_val") == "") {
                return [];
            }
            var data = JSON.parse(wmpSelector.attr("select_val"));
            return data;
        },
        set: function (data) {
            if (!data) { return; }
            var $this = $(this);
            /*判断输出模式-是否需要带出工号*/
            var show_userid = $this.attr("show-userid");
            var set_text = exp_name = set_value = "";
            var set_item = [];
            if (data[0].Text == undefined & data[0].Value == undefined) {
                for (var start = 0; start < data.length; start++) {
                    var name = data[start].name;
                    var no = data[start].no;
                    var pname = data[start].pname;
                    var pno = data[start].pno;

                    set_value += no + ",";
                    if (show_userid) {
                        set_text += name + "(" + no + "),";
                    } else {
                        set_text += name + ",";
                    }
                    exp_name += name + "(" + no + "),";

                    set_item.push({
                        name: name,
                        no: no,
                        pname: pname,
                        pno: pno,
                        four_center_id: "",
                        four_center_name: "",
                        system_name: ""
                    });
                }

                if (set_text != "") {
                    set_text = set_text.substring(0, set_text.length - 1);
                }
            }
            else {
                set_text = data[0].Text;
                set_value = data[0].Value;
                var text_item = [], value_item = [];
                if (set_text != undefined && set_text != "") {
                    if (set_text.indexOf(',') > -1 && set_value.indexOf(',') > -1) {
                        text_item = set_text.split(',');
                    } else {
                        text_item.push(set_text);
                    }
                } else {
                    set_text = "";
                }

                if (set_value != undefined && set_value != "") {
                    if (set_text.indexOf(',') > -1 && set_value.indexOf(',') > -1) {
                        value_item = set_value.split(',');
                    } else {
                        value_item.push(set_value);
                    }
                } else {
                    set_value = "";
                }

                if (!set_text && !set_value) {
                    $(this).find("input.selector_text").val(set_text).attr("select_val", JSON.stringify([]));
                    return;
                }

                //---补齐位数差
                if (value_item != undefined && value_item.length > 0) {
                    if (text_item.length < value_item.length) {
                        for (var start = text_item.length; start < value_item.length; start++) {
                            text_item[start] = "";
                        }
                    }
                }

                var exp_name = "";
                for (var start = 0; start < value_item.length; start++) {
                    set_item.push({
                        name: text_item[start],
                        no: value_item[start],
                        pname: "",
                        pno: "",
                        four_center_id: "",
                        four_center_name: "",
                        system_name: ""
                    });

                    exp_name += text_item[start] + "(" + value_item[start] + "),";
                }
            }

            if (set_text == "") {
                set_text = set_value;
            }

            if ($(this).attr("id") == "Header_applicantUser" || show_userid) {
                if (exp_name != "") {
                    exp_name = exp_name.substring(0, exp_name.length - 1);
                }
                set_text = exp_name;
            }

            $(this).find("input.selector_text").val(set_text).attr("select_val", JSON.stringify(set_item));
        },
        clear: function () {
            $(this).find("input").val("").attr("select_val", "");
        },
        user: function (data) {
            var options = {
                title: window.LangMsg['msg_wmp_select_user'],
                url: "/tappUser/SelectUser",
                search_url: "/tappUser/SearchUser",
                init: {
                    no: data ? data.deptId || "10001" : "10001",
                    name: window.LangMsg['msg_wmp_mindray']
                },
                multy: false,
                edit: false
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        },
        dept: function (data) {
            var options = {
                title: window.LangMsg['msg_wmp_choose_depart'],
                url: "/tappDept/SelectDept",
                //search_url: "/wmp/api/searchdeptanduser",
                search_url: "/tappDept/SearchDept",
                init: {
                    no: data ? data.deptId || "10001" : "10001",
                    name: window.LangMsg['msg_wmp_mindray']
                },
                leaf_load: false,
                multy: false,
                circle: true
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        },
        cost: function (data) {
            var options = {
                multy: false,
                title: window.LangMsg['msg_wmp_select_cost'],
                url: "/osfinance/api/cost",
                search_url: "/osfinance/api/cost",
                param: {
                    Language: "2052",
                    Country: "cn",
                    Parent: "MR",
                    Company: "",
                    IsFrozen: false
                },
                type: "cost"
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        },
        company: function (data) {
            var options = {
                title: window.LangMsg['msg_wmp_filiale'],
                url: "/tappOrgan/SelectOrgan",
                search_url: "/tappOrgan/SearchOrgan",
                leaf_load: false,
                multy: false,
                circle: true,
                init: {
                    no: "all"
                },
                wechat_company: true
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        },
        project: function (data) {
            var options = {
                title: "项目单位",
                url: "/wmp/api/project",
                search_url: "/wmp/api/project/search",
                type: "project",
                leaf_load: true,
                multy: false,
                circle: true,
                init: {
                    //20180601 全振英 可传入deptId，增加CompanyCode
                    no: data ? data.deptId || "10000002" : "10000002",
                    companyCode: data ? data.companyCode || "1000" : "1000",
                }
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        },
        job: function (data) {
            var options = {
                title: "职位",
                url: "/wmp/api/project",
                search_url: "/wmp/api/project/search",
                type: "job",
                multy: false,
                circle: true,
                init: {

                }
            };
            options = $.extend(options, data);
            return this.WmpSelect("init", options);
        }
    };
    $.fn.WmpSelect = function (method) {
            if (methods[method]) {
                return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
            } else if (typeof method === 'object' || !method) {
                return methods.init.apply(this, arguments);
            } else {
                $.error('Method' + method + 'does not exist');
            }
    };
})($);
function _input_change(_this) {
    var _val = $(_this).val().trim(),
         json = JSON.stringify([{
             "name": _val,
             "no": _val,
             "pname": "",
             "pno": ""
         }]);
    $(_this).attr("select_val", json);
};
